<?php
header('Access-Control-Allow-Origin:*');
/**
 * 通用函数库
 */
function result(int $code, String $msg, array $data)
{
    $res = array(
        "code" => $code,
        "message" => $msg,
        "data" => $data
    );
    return $res;
}

function resultmsg(int $code, String $msg)
{
    $res = array(
        "code" => $code,
        "message" => $msg
    );
    return $res;
}

/**
 * 生成随机字符串
 */
function generateRandomString($length)
{
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomString;
}
/**
 * 用反斜线转义字符串
 * @param arr 待转义的数组
 * @return arr 转义后的数组
 */

function _addslashes($arr){
    foreach ($arr as $k => $v){
        if (is_string($v)){
            $arr[$k] = addslashes($v);
        }else if(is_array($v)){
            $arr[$k] = _addslashes($v);
        }
    }
    return $arr;
}